package pl.edu.pw.stud.ltrzaska.policy.xml;

import java.util.ArrayList;
import java.util.List;

import pl.edu.pw.stud.ltrzaska.policy.entity.File;
import pl.edu.pw.stud.ltrzaska.policy.entity.Filesystem;
import pl.edu.pw.stud.ltrzaska.policy.entity.FilesystemObject;
import pl.edu.pw.stud.ltrzaska.policy.entity.FilesystemTime;
import pl.edu.pw.stud.ltrzaska.policy.entity.PolicyValidator;

import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class FileConverter implements Converter {

	@Override
	public boolean canConvert(Class clazz) {
		return (clazz == File.class);
	}

	@Override
	public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) {
		// TODO Auto-generated method stub
	}

	@Override
	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		File f = new File();
		
		ConverterCommons.preLoopUnmarshal(reader, f);
		while (reader.hasMoreChildren()) {
			reader.moveDown();
			
			String attrName = reader.getNodeName();
			ConverterCommons.inLoopUnmarshal(reader, context, f);
						
			reader.moveUp();
		}
		return f;
	}
}
